<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
		<title>{:lang('pay')}</title>		
		<link rel="stylesheet" type="text/css" href="NC_PAY_WEB_CSS/wechatNative.css">
	</head>

	<body>
		<script type="text/javascript">
		var jsApiParams = {$jsApiParameters};
		
		function jsApiCall(){
			WeixinJSBridge.invoke('getBrandWCPayRequest', jsApiParams,
				function(res){
				WeixinJSBridge.log(res.err_msg);
					if (res.err_msg == "get_brand_wcpay_request:ok") {
				     	// 支付成功
				     	location.href = "{:append_url_params($pay_data.return_url, ['out_trade_no' => $pay_data.out_trade_no])}";
		      		} else if (res.err_msg == "get_brand_wcpay_request:cancel") {
		      			// 取消支付
		      			location.href = "{:append_url_params($pay_data.return_url, ['out_trade_no' => $pay_data.out_trade_no])}";
		      		}else if (res.err_msg == "get_brand_wcpay_request:fail") {
		  				// 支付失败
		  				location.href = "{:append_url_params($pay_data.return_url, ['out_trade_no' => $pay_data.out_trade_no])}";
		      		}else {
		      			alert(JSON.stringify(res));
		      		}
				}
			);
		}
		
		function WeixinPay(){
			if(jsApiParams !=null && jsApiParams.return_code == "FAIL"){
				alert(JSON.stringify(jsApiParams));
			}else{
				if(typeof WeixinJSBridge == "undefined"){
					if(document.addEventListener ){
						document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
					}else if (document.attachEvent){
						document.attachEvent('WeixinJSBridgeReady', jsApiCall);
						document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
					}
				}else{
					jsApiCall();
				}
			}
		}
		
		WeixinPay();
		
		
		
		</script>
	</body>
</html>

